/*
 * EliminaAccountServlet
 * 
 * Author: Carmine Colicino, Luigi Di Martino
 * Version: 1.0
 * 
 * 2014 - Copyright by Team 6 - University of Salerno
*/

package it.unisa.udocs.gestioneSistema;

import it.unisa.udocs.data.Account;
import it.unisa.udocs.facade.FacadeSistema;
import it.unisa.udocs.facade.IFacadeSistema;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class EliminaAccountServlet
 */

public class EliminaAccountServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EliminaAccountServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, 
			HttpServletResponse response) 
					throws ServletException, IOException {
		
		IFacadeSistema facSis = new FacadeSistema();
		
		//Prende dalla sessione l'account visualizzato
		Account account = (Account) 
				request.getSession().getAttribute("accountVisualizzato");
		
		//Toglie dalla sessione l'account visualizzato
		request.getSession().removeAttribute("accountVisualizzato");
		
		facSis.eliminaAccount(account);
				
		System.out.println("ACCOUNT ELIMINATO :" + account.getUsername());
	}

}
